home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / stlogin4.lzh / UX_MISC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-30  |  2.5 KB  |  135 lines

  1. /* Miscellaneous functions. Kees Lemmens; Aug 1992
  2.  
  3.    Any questions or suggestions about this program can be send to:
  4.    lemmens@dv.twi.tudelft.nl
  5. */
  6.  
  7. #ifdef __PUREC__
  8. #include <tos.h>
  9. #else
  10. #include <osbind.h>
  11. #endif
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <pwd.h>
  16. #include <signal.h>
  17. #include <time.h>
  18. #include <cookie.h>
  19. #include "ux_misc.h"
  20.  
  21. #undef sleep(s)    /* for running under TOS */
  22.  
  23. void Delay(clock_t ticks)    /* 1 tick =1/1000 sec */
  24. {    clock_t start = clock();
  25.  
  26.     while((clock() - start) * (1000 / CLK_TCK) < ticks);
  27. }
  28.  
  29.  
  30. int RunningMint(void)
  31. {    long suret;
  32.     int flag=0;
  33.     COOKIE *jar;
  34.  
  35.     if(Super((void *)1L)==0L)
  36.     {    suret=Super(0L);
  37.         jar=*CJAR;
  38.         Super((void *)suret);
  39.     }
  40.     else
  41.         jar=*CJAR;
  42.     
  43.     while(jar->tag.aslong != 0)
  44.     {    if(!strncmp(jar->tag.aschar,"MiNT",4))
  45.             flag=1;
  46. #ifdef DEBUG
  47.     printf("cookie: %.4s, value: %lx\n",jar->tag.aschar,jar->value);
  48. #endif
  49.         jar++;
  50.     }
  51.     return flag;
  52. }
  53.  
  54. void MyDummy(void)
  55. {  return;
  56. }
  57.  
  58. void Mysleep(unsigned seconds)
  59. {
  60. /* Avoid heavy system load while waiting for input :
  61.    Standard sleep functions in PURE C cause enormous load on a
  62.    multitasking system, as they are stupid loops !!
  63. */
  64.     void sleep(unsigned);
  65.     
  66.     if(RunningMint())
  67.     {    Psignal(SIGALRM,MyDummy);
  68.         Talarm(seconds);    /* set alarm time */
  69.         (void)Pause();        /* wait for alarm */
  70.     }
  71.     else sleep(seconds);
  72. }    
  73.  
  74. char *ux2dos(char *string)    /* convert / to \ */
  75. {    char *tmp;
  76.     while((tmp=strchr(string,'/')) != NULL)
  77.         *tmp='\\';
  78.     return string;
  79. }
  80.  
  81. void *encrypt(char *passwd)
  82. {    int x;        /* simple passwd encrypt/decript routine */
  83.  
  84.     for(x=0;x<strlen(passwd);x++)
  85.         passwd[x] ^= 19+x;
  86.  
  87.     return passwd;
  88. }
  89.  
  90. int check_pw(char *login_pw,struct passwd *pwent)
  91. {
  92.     if(strcmp(encrypt(login_pw),pwent->pw_passwd))
  93.         return -1;
  94.     return 0;
  95. }
  96.  
  97. void tty_flush(void)
  98. {    /* Cconis() determines if a character is available */
  99.     while (Delay(50),Cconis() == -1)
  100.         Cnecin();
  101. }
  102.  
  103. void Put(char *cmd)
  104. {    int x;
  105.  
  106.     for(Delay(50),x=0;x<strlen(cmd);x++)
  107.         Cconout(cmd[x]);
  108. }
  109.  
  110. void Get(char *str,int nr,int mode)
  111. {    int cnt=0;    /* mode 0: no echo ; mode=1 echo */
  112.     while(*str=Cnecin(),cnt++ < nr)
  113.     {    if (mode) Cconout(*str);
  114.         if(*str == '\15' || *str == '\n')
  115.         {    *str = '\0';
  116.             return;
  117.         }
  118.         str++;
  119.     }
  120. }
  121.  
  122. int mk_devnm(char *dev,char *arg)
  123. {    char *devpath  =DEV;
  124.  
  125.     if(arg==NULL) return -1;
  126.     if(strchr(arg,'\\') != NULL || strchr(arg,':') != NULL)
  127.         strcpy(dev,arg);
  128.     else
  129.     {    strcpy(dev,devpath);
  130.         strcat(dev,arg);
  131.     }
  132.     ux2dos(dev);
  133.     return 0;
  134. }
  135.